package com.white.toolkit

import android.net.Uri
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.white.camlib.CameraEngine
import com.white.camlib.CameraKit
import com.white.loglib.L
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_take_picture.*
import kotlinx.android.synthetic.main.activity_take_picture.root
import java.io.File

class TakePictureActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_take_picture)
        root.post{
            CameraEngine.getInstance().attachParent2Display(root, true, 0, 0,
                windowManager.defaultDisplay.rotation,null, null)
        }
    }

    fun click(view: View?) {
        val path = File(getExternalFilesDir(null), "test.jpg")
        CameraEngine.getInstance().takePicture(path.absolutePath,  object : CameraKit.PictureCallback{
            override fun onTakePicture(path: String?) {
                L.e("拍照成功")
                result.setImageURI(Uri.fromFile(File(path)))
            }

        })
    }


    override fun onDestroy() {
        super.onDestroy()
        CameraEngine.getInstance().detach()
    }
}